package com.situ.water_system.service.impl;

import com.situ.water_system.pojo.SyEmpmenupower;
import com.situ.water_system.mapper.SyEmpmenupowerMapper;
import com.situ.water_system.service.SyEmpmenupowerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Service
public class SyEmpmenupowerServiceImpl extends ServiceImpl<SyEmpmenupowerMapper, SyEmpmenupower> implements SyEmpmenupowerService {
    @Autowired
    private SyEmpmenupowerMapper dao;

    /**
     * 查询一个员工菜单权限
     * @param id
     * @return
     */
    public List<SyEmpmenupower> showid(int id){
        Map<String,Object> hashMap = new HashMap();
        hashMap.put("EmpID",id);
        return dao.selectByMap(hashMap);
    }
    /***
     * 删除原菜单权限
     */
    @Transactional
    public void   delmenu(Integer[] id){
        for (int i=0;i<id.length;i++){
            Map<String,Object> hashMap = new HashMap();
            hashMap.put("EmpID", id[i]);
            dao.deleteByMap(hashMap);
        }
    }
    @Transactional
    public int addmenu(Integer[] EmpId,Integer[] menuId){
        this.delmenu(EmpId);
        System.out.println(EmpId.length);
        for (int i=0;i<EmpId.length;i++){
            for (int b=0;b<menuId.length;b++){
            SyEmpmenupower syEmpmenupower = new SyEmpmenupower();
            syEmpmenupower.setEmpID(EmpId[i]);
            syEmpmenupower.setMenuID(menuId[b]);
            dao.insert(syEmpmenupower);
            }
        }
        return 1;
    }
}
